package com.dataart.productshop.dao.impl;

import com.dataart.productshop.dao.LecturerDao;
import com.dataart.productshop.model.boiko.informationsystem.Kathedra;
import com.dataart.productshop.model.boiko.informationsystem.Lecturer;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LecturerDaoImpl extends BaseDaoImpl<Lecturer> implements LecturerDao{
    public LecturerDaoImpl() {
        super(Lecturer.class);
    }

    public List<Lecturer> getLecturerByName(String name){
        return getByName(name);
    }

    public void removeByName(String name){
        List<Lecturer> selected = getByName(name);
        if(selected != null){
            for (Lecturer lecturer : selected) {
                delete(lecturer.getId());
            }
        }
    }

    public List<Lecturer> getByName(String name){
        return createCriteria(Lecturer.class)
                .add(Restrictions.eq("name", name))
                .list();
    }

    public List<Lecturer> getLecturerByNameQuery(String query){
        return createCriteria(Lecturer.class)
                .add(Restrictions.like("name", "%"+query+"%"))
                .list();
    }
}
